Skip to content

feat(lp-reward): implement liquidity provider reward contract for key pairs - #1004

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
CathyZaks:fix/issue-1002-lp-reward-contract
Sep 28, 2026
Merged

Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
CathyZaks:fix/issue-1002-lp-reward-contract

Conversation

@CathyZaks

Copy link
Copy Markdown
Contributor

Header

Liquidity Provider Reward Contract for Key Pairs

Problem

Liquidity providers on key pairs currently lack a dedicated reward mechanism to lock tokens as liquidity, earn a proportional share of trading fees generated by pair trading activity, and claim accumulated fee rewards or withdraw liquidity with their accrued yield.

Solution

Implemented a dedicated LpRewardContract crate (and integrated equivalent entrypoints into CreatorKeysContract) using high-precision accumulator accounting (SCALE = 1e12) and basis-point proportional share calculations (BPS_SCALE = 10_000):

  • add_liquidity(key_id, amount) / add_liquidity_for(caller, key_id, amount): Locks tokens, calculates proportional pool share in basis points, records the position, and emits an LPAdded event.
  • remove_liquidity(lp_id): Computes accrued fee rewards plus principal, updates pool totals, clears the position, and emits an LPRemoved event.
  • claim_lp_rewards(lp_id): Claims pending accrued fee rewards without removing principal liquidity and emits an LPRewardClaimed event.
  • get_lp_position(lp_id): Returns contribution amount, basis-point pool share, and current pending reward amount.
  • accrue_trading_fee(key_id, fee_amount): Accrues trading volume fees into the key pool reward accumulator for proportional distribution across all active liquidity providers.

Changes

  • lp-reward-contract/Cargo.toml: Created workspace member crate with Soroban SDK dependencies and test utilities.
  • lp-reward-contract/src/lib.rs: Core LpRewardContract implementation with data structures, error handling, events, and accumulator fee distribution.
  • lp-reward-contract/src/test.rs: Unit test suite covering proportional shares, fee accrual over trading volume, reward claiming, liquidity removal, event emission, and parameter validation.
  • Cargo.toml: Added "lp-reward-contract" to workspace members.
  • creator-keys/src/lp_reward.rs: Matching module for LP reward tracking in the core creator-keys contract.
  • creator-keys/src/lib.rs: Exposed LP reward entrypoints on CreatorKeysContract.
  • creator-keys/src/test_lp_reward.rs: Integration tests verifying client invocations and fee distributions on CreatorKeysContract.
  • .gitignore: Added general pattern for **/test_snapshots/.

Testing

  • cargo fmt --all -- --check: Passed
  • cargo clippy --workspace --all-targets -- -D warnings: Passed (0 warnings)
  • cargo build --workspace: Passed
  • cargo test -p lp-reward-contract: 7 passed, 0 failed
  • cargo test -p creator-keys --lib test_lp_reward: 4 passed, 0 failed

Closes #1002

@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@CathyZaks Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

… pairs

- Implement LpRewardContract with proportional pool share tracking and accumulator-based fee distribution
- Add add_liquidity, remove_liquidity, claim_lp_rewards, and get_lp_position entrypoints
- Expose LP reward management functions on CreatorKeysContract
- Emit LPAdded and LPRewardClaimed contract events
- Add comprehensive test suites verifying proportional share computation and fee accruals
@CathyZaks
CathyZaks force-pushed the fix/issue-1002-lp-reward-contract branch from 0615ff5 to fd7b035 Compare September 27, 2026 17:34
@Chucks1093
Chucks1093 merged commit c8c156c into accesslayerorg:main Sep 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build LP reward contract for liquidity providers on key pairs

2 participants